package mystruts;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import vo.Person;

import com.opensymphony.xwork2.ActionSupport;

import dao.PersonDao;

public class PersonAction extends ActionSupport{
	public String addform(){
		this.LOG.info("Person.addform");
		return "addform";
	}
	public String add(){
		this.LOG.info("Person.add");
		this.LOG.info("username:"+vo.getName());
		PersonDao dao=new PersonDao();
		dao.insert(vo);
		java.util.ArrayList<Person> list=shopcar();
		list.add(vo);
		return "add";
	}
	public String list(){
		this.LOG.info("Person.list");
		this.setRslist(shopcar());
		return "list";
	}
	public String updateform(){
		this.LOG.info("Person.updateform");
		this.setVo(shopcar().get(index));
		return "updateform";
	}
	public String update(){
		this.LOG.info("Person.update");
		//this.LOG.info("username:"+vo.getName());
		//PersonDao dao=new PersonDao();
		//dao.insert(vo);
		java.util.ArrayList<Person> list=shopcar();
		list.set(index,vo);
		return list();
	}
	public String delete(){
		this.LOG.info("Person.delete");
		//this.LOG.info("username:"+vo.getName());
		//PersonDao dao=new PersonDao();
		//dao.insert(vo);
		java.util.ArrayList<Person> list=shopcar();
		list.remove(index);
		return list();
	}
	java.util.ArrayList<Person> shopcar()
	{
		HttpSession session=ServletActionContext.getRequest().getSession();
		java.util.ArrayList<Person> list=(java.util.ArrayList<Person>)session.getAttribute("list");
		if(list==null)
		{
			list=new java.util.ArrayList<Person>();
			session.setAttribute("list", list);
		}
		return list;
	}
	Person vo;
	public Person getVo() {
		return vo;
	}
	public void setVo(Person vo) {
		this.vo = vo;
	}
	java.util.ArrayList<Person> rslist;
	public java.util.ArrayList<Person> getRslist() {
		return rslist;
	}
	public void setRslist(java.util.ArrayList<Person> rslist) {
		this.rslist = rslist;
	}
	int index;
	public int getIndex() {
		return index;
	}
	public void setIndex(int index) {
		this.index = index;
	}
}
